#include <EEPROM.h>

int automodeADDR = 0 ; //内存地址0开始
int Temp1ADDR  = 1 ; //浮点数占4个位
int Temp2ADDR  = 5 ; //浮点数占4个位


bool automode ;
float T1 ; //浮点数占4个位
float T2 ; //浮点数占4个位

void writeautomode(bool temp)
{
  EEPROM.put(automodeADDR, temp);
  EEPROM.commit();
  Serial.println("Write MODE:" + (String)temp + " OK!\n" );
}

void writeT1(float temp)
{
  EEPROM.put(Temp1ADDR, temp);
  EEPROM.commit();
  Serial.println("Write T1:" + (String)temp + " OK!\n" );
}

void writeT2(float temp)
{
  EEPROM.put(Temp2ADDR, temp);
  EEPROM.commit();
  Serial.println("Write T2:" + (String)temp + " OK!\n" );
}



void readautomode ()
{
  EEPROM.get(automodeADDR, automode);
  Serial.println((String)automode + "\n" );
  if ( automode != NULL) {  //判断是否空值
    Serial.println("MODE:" + (String)automode + "\n" );
  }
  else {
    writeautomode(true);
  }


}

void readT1 ()
{
  EEPROM.get(Temp1ADDR, T1);
  Serial.println((String)T1 + "\n" );
  if (T1 != NULL) { //判断是否空值
    Serial.println("readT1:" + (String)T1 + "\n" );
  }
  else {
    writeT1(11.0);
  }
}

void readT2()
{
  EEPROM.get(Temp2ADDR, T2);
  Serial.println((String)T2 + "\n" );
  if (T2 != NULL) { //判断是否空值
    Serial.println("readT2:" + (String)T2 + "\n" );
  }
  else {
    writeT2(66.0);
  }
}



void setup() {
  Serial.begin(115200);
  EEPROM.begin(512);
  delay(1000);
  Serial.println("System is on!\n" );
  readautomode();
  readT1();
  readT2();
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}